package cn.bluemobi.app.controller.collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.app.core.controller.AppBaseController;
import cn.bluemobi.app.entity.output.Collections;
import cn.bluemobi.app.service.CollectionService;
import cn.bluemobi.common.core.dto.Dto;
import cn.bluemobi.common.core.dto.ListDto;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * 
 * @author lvxh
 * 
 */
@Controller
@RequestMapping("/collection")
@Api(description = "收藏", value = "collection")
public class CollectionController extends AppBaseController {

	@Autowired
	private CollectionService collectionService;

	@ApiOperation(value = "查询商品收藏", httpMethod = "POST")
	@RequestMapping("/findCollectionList")
	@ResponseBody
	public ListDto<Collections> findCollectionList(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("类型(0商品，1商户)") @RequestParam("type") String type) {
		return collectionService.findCollectionList(memberId, type);
	}

	@ApiOperation(value = "添加收藏", httpMethod = "POST")
	@RequestMapping("/saveOrUpdateCollection")
	@ResponseBody
	public Dto<Collections> saveOrUpdateCollection(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("类型(0商品{merchantId,commodityId必传}，1商户{merchantId必传})") @RequestParam("type") String type,
			@ApiParam("商户ID") @RequestParam("merchantId") String merchantId,
			@ApiParam("商品ID") @RequestParam(value = "commodityId", required = false) String commodityId) {
		return collectionService.saveOrUpdateCollection(memberId, merchantId,
				commodityId, type);
	}

	@ApiOperation(value = "删除收藏", httpMethod = "POST")
	@RequestMapping("/deleteCollection")
	@ResponseBody
	public Dto<Object> deleteCollection(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("会员ID") @RequestParam("collectionId") String collectionId) {
		return collectionService.deleteCollection(memberId, collectionId);
	}

}
